Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute @Before annotated methods before REST requests #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

redrezo
Copy link

@redrezo redrezo commented Apr 9, 2014

patched HttpJUnitRunner to support this
added @HttpConfig annotation and RuleStrategy enum to configure behavior
default behavior is unchanged

example:

@RunWith(HttpJUnitRunner.class)
@HttpConfig(ruleStrategy=RuleStrategy.HTTP_CALL_AFTER_BEFORE)
public class MyTest {
    @Rule
    public Destination destination = new Destination(this, "http://localhost:" + System.getProperty( "org.osgi.service.http.port" ));

    @Context
    private Response response;

    @Before
    public void before() {
        System.err.println("Test#before()");
        Bundle bundle = FrameworkUtil.getBundle(Test.class);
        BundleContext bundleContext = bundle.getBundleContext();
        ServiceReference<WebService> serviceReference = bundleContext.getServiceReference(WebService.class);
        WebService service = bundleContext.getService(serviceReference);
        service.setName("Foo");
    }

    @org.junit.Test
    @HttpTest(method=Method.GET, path="/services/hello")
    public void testServiceCall() {
        System.err.println("Test#testServiceCall()");
        assertOk(response);
        assertEquals("Hello Foo", response.getBody());
    }
}


@Path("/")
public class WebService {

    private String name = "World";

    @GET
    @Path("/hello")
    public String helloWorld() {
        System.err.println("WebService#helloWorld()");
        return "Hello " + name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

before rest services are executed. configurable via a new @HttpConfig
annotation. default behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant